from geoserver.catalog import Catalog
# def create_coveragestore2(self, name, data_url, workspace=None, overwrite=False):
#         if not overwrite:
#             try:
#                 store = self.get_store(name, workspace)
#                 msg = "There is already a store named " + name
#                 if workspace:
#                     msg += " in " + str(workspace)
#                 raise ConflictingDataError(msg)
#             except FailedRequestError:
#                 # we don't really expect that every layer name will be taken
#                 pass

#         if workspace is None:
#             workspace = self.get_default_workspace()
#         headers = {
#             "Content-type": "text/plain",
#             "Accept": "application/xml"
#         }

#         ext = "geotiff"

#         cs_url = url(self.service_url,
#             ["workspaces", workspace.name, "coveragestores", name, "external." + ext],
#             { "configure" : "first", "coverageName" : name})

#         headers, response = self.http.request(cs_url, "PUT", data_url, headers)
#         self._cache.clear()
#         if headers.status != 201:
#             raise UploadError(response)
if __name__=="__main__":
    geourl = "http://47.92.159.240:9023/geoserver/rest"  # the url of geoserver
    geocat = Catalog(geourl, username="admin", password="ucare_admin2016")  # create a Catalog object

    store_name = "SXXXXXC"
    data_url = "file:D:/data_dir2/TIFF4326/sxc4326.tif"
    geocat.create_coveragestore2(store_name, data_url,'TIFF')
    print('success')